package com.liang.sendpsy.service.impl;

import com.liang.sendpsy.service.MailService;
import com.liang.sendpsy.utils.HttpUtils;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;

@Service
public class MailServiceImpl implements MailService {
    public static final ThreadLocal<String> threadLocal =new ThreadLocal<>();
    @Autowired
    JavaMailSender javaMailSender;

    @Override
    public void sendMail(String username, String toUser) throws Exception {
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setFrom(username);
        simpleMailMessage.setTo(toUser);
        simpleMailMessage.setSubject("潘小雨吃屁" + new Date());

        HttpResponse get = HttpUtils.doGet("https://chp.shadiao.app", "/api.php", "get",
                new HashMap<>(), new HashMap<>());
        String text = EntityUtils.toString(get.getEntity());
        simpleMailMessage.setText(text);
        threadLocal.set(text);
        javaMailSender.send(simpleMailMessage);
    }




}
